package org.example.testcode.bean;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.example.testcode.annotation.ESField;
import org.example.testcode.enumeration.ESAnalyzer;
import org.example.testcode.helper.IESMappingType;
import org.example.testcode.helper.MD5Helper;

import java.io.Serializable;
import java.lang.reflect.Field;

@Setter
@Getter
@ToString
public class TopicEsInfo implements IESMappingType, Serializable {

    /**
     * 来源：cnblog
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String source;

    /**
     * 文档ID
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed, isStore = true, fielddata = true)
    private String docId;


    /**
     * 话题ID
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String topicId;

    /**
     * 链接
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String link;

    /**
     * 名称
     */
    @ESField(analyzerType = ESAnalyzer.standard)
    private String title;

    /**
     * 作者
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String author;

    /**
     * 图片链接
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String picUrl;

    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String picUrl2;


    /**
     * 标签
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String tags;

    /**
     * 发布时间
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private String postTime;

    /**
     * 点击数量
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private int clickCount;


    /**
     * 喜欢数量
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private int likeCount;


    /**
     * 热门：0否；1是
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private int hot;


    /**
     * 难度等级：0低；1中；2高；3难
     */
    @ESField(analyzerType = ESAnalyzer.not_analyzed)
    private int difficulty;

    /**
     * 导读内容
     */
    @ESField(analyzerType = ESAnalyzer.standard)
    private String navText;

    /**
     * 正文内容
     */
    @ESField(analyzerType = ESAnalyzer.standard)
    private String bodyText;


    @Override
    public String generateDocId() {
        //要唯一性，不能随机生成
        //return String.format("%s%s", System.currentTimeMillis(), link.hashCode());
        if (null != this.getLink() && this.getLink().length() > 0) {
            //return MD5Helper.GetTopicUnionId(link);
            return docId;
        }
        return "0";
    }

    @Override
    public Field[] foundTypeField() {
        return this.getClass().getDeclaredFields();
    }
}
